// eee.Sheffield.PZ.Imaging
//
// Copyright ?Ping Zou, 2006
// sg71.cherub@gmail.com

using System;
using System.Collections.Generic;
using System.Text;
using eee.Sheffield.PZ.Math;
using System.Drawing;
using System.Drawing.Imaging;

namespace eee.Sheffield.PZ.Imaging.ImageFilter
{
    public class GaussianSmoothing :ImageFilter//, IGraylevelImageFilter
    {
        #region Fields
        /// <summary>
        /// standard deviation of the distribution
        /// </summary>
        private double _sigma;
        //private string _flag = "[Image -> Smooth -> GaussianSmoothing]";
        #endregion

        #region Properties
        public double Sigma { get { return _sigma; } set { _sigma = value; } }
        //public string Flag() { return _flag; }
        //public string Log() { return _log; }
        #endregion

        #region constructor
        /// <summary>
        /// empty constructor
        /// </summary>
        public GaussianSmoothing() : this(0) { }
        /// <summary>
        /// imput standard deviation of the distribution
        /// </summary>
        /// <param name="sigma"></param>
        public GaussianSmoothing(double sigma)
        {
            _flag = "[Image -> Smooth -> GaussianSmoothing]";
            _sigma = sigma;
        }
        #endregion

        #region Apply filter
        //public Bitmap ApplyGraylevelImageFilter(Bitmap srcImage) { return Apply(srcImage, out _log); }
        //public PZMath_matrix ApplyDoubleGraylevelImageFilter(PZMath_matrix srcMatrix) { return ApplyDouble(srcMatrix, out _log); }

        //private Bitmap Apply(Bitmap srcImage, out string logText)
        //{
        //    PZMath_matrix srcMatrix = _converter.ConvertGraylevelBitmapToMatrix(srcImage);
        //    PZMath_matrix dstMatrix = ApplyDouble(srcMatrix, out logText);
        //    Bitmap dstImage = _converter.ConvertMatrixToGraylevelBitmap(dstMatrix);
        //    return dstImage;
        //}     

        protected override PZMath_matrix ApplyDoubleGraylevelImageFilter(PZMath_matrix srcMatrix, out string logText)
        {
            // do two 1D Gaussian filtering
            GaussianX gaussianX = new GaussianX(_sigma);
            GaussianY gaussianY = new GaussianY(_sigma);
            
            PZMath_matrix XDirection = gaussianX.ApplyDoubleGraylevelImageFilter(srcMatrix);
            //string gaussianXLog = gaussianX.Log;
            PZMath_matrix YDirection = gaussianY.ApplyDoubleGraylevelImageFilter(XDirection);
            //string gaussianYLog = gaussianY.Log;
            logText = "succeeds.";
            return YDirection;
        } // ApplyDoubleGraylevelImageFilter()

        protected override PZMath_matrix[] ApplyDoubleColourImageFilter(PZMath_matrix[] srcMatrixArray, out string logText)
        {            
            // do two 1D Gaussian filtering
            GaussianX gaussianX = new GaussianX(_sigma);
            GaussianY gaussianY = new GaussianY(_sigma);

            PZMath_matrix[] xDirectionArray = gaussianX.ApplyDoubleColourImageFilter(srcMatrixArray);
            PZMath_matrix[] dstMatrixArray = gaussianY.ApplyDoubleColourImageFilter(xDirectionArray);
            logText = "succede";
            return dstMatrixArray;
        } // ApplyDoubleColourImageFilter()
        #endregion
    }
}
